//
//  WZExecutorCheckController.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/7/5.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "WZExecutorCheckController.h"
#import "WZDetailTask.h"

@interface WZExecutorCheckController ()

@property (weak, nonatomic) IBOutlet UILabel *taskName;
@property (weak, nonatomic) IBOutlet UILabel *desc;
@property (weak, nonatomic) IBOutlet UILabel *beginTime;
@property (weak, nonatomic) IBOutlet UILabel *endTime;
@property (weak, nonatomic) IBOutlet UILabel *projectName;
@property (weak, nonatomic) IBOutlet UILabel *statusName;
@property (weak, nonatomic) IBOutlet UILabel *progress;
@property (weak, nonatomic) IBOutlet UILabel *exturoName;
@property (weak, nonatomic) IBOutlet UILabel *assignerName;

@property (nonatomic, strong) WZDetailTask *detailTask;

@end

@implementation WZExecutorCheckController

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.tableView.tableFooterView.backgroundColor = [UIColor greenColor];
    
    UIButton *refuseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [refuseBtn setTitle:@"拒绝" forState:UIControlStateNormal];
    refuseBtn.backgroundColor = WZRGBColor(247, 187, 66);
    refuseBtn.frame = CGRectMake(0, HARDWARE_SCREEN_HEIGHT - 44 - 64, HARDWARE_SCREEN_WIDTH * 0.5, 44);
    [refuseBtn addTarget:self action:@selector(refuseBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:refuseBtn];
    
    
    UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [agreeBtn setTitle:@"同意" forState:UIControlStateNormal];
    agreeBtn.backgroundColor = WZRGBColor(94, 196, 206);
    agreeBtn.frame = CGRectMake(HARDWARE_SCREEN_WIDTH - refuseBtn.width, HARDWARE_SCREEN_HEIGHT - 44, HARDWARE_SCREEN_WIDTH * 0.5, 44);
    [agreeBtn addTarget:self action:@selector(agreeBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:agreeBtn];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupTableView];
    
    [self getTaskDetailInfor];
    
}


- (void)setupTableView {
    
    self.tableView.backgroundColor = WZRGBColor(245, 246, 249);
    self.title = @"任务详情";
    self.tableView.tableFooterView = [[UIView alloc] init];
    
}


/**任务详细信息*/
- (void)getTaskDetailInfor {
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"name"] = self.oaUserName;
    params[@"pwd"] = self.oaPwd;

    params[@"taskId"] = self.taskId;
    
    [NetWorkShare getTaskDetailInforWithParams:params SuccessHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            
            if ([[responseObject objectForKey:@"success"] boolValue]) {
                
                self.detailTask = [WZDetailTask objectWithKeyValues:responseObject[@"detail"]];
                
                [self loadData];
                
                [self.tableView reloadData];
                
                WZLog(@"%@", responseObject);
            } else {
                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
            }
        } else {
            
            [MBProgressHUD showError:UNKNOWNERROR];
        }
    } FailureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD showError:NETWORKNERROR];
        WZLog(@"error = %@", error);
    }];
    
}

- (void)loadData {
    
    self.taskName.text = self.detailTask.taskName;
    self.desc.text = self.detailTask.remark;
    self.beginTime.text = self.detailTask.planExecBeginDate;
    self.endTime.text = self.detailTask.planExecEndDate;
    self.projectName.text = self.detailTask.projectName;
    self.exturoName.text = self.detailTask.executorName;
    self.assignerName.text = self.detailTask.assignerName;
    self.statusName.text = self.detailTask.statusName;
    self.progress.text = [NSString stringWithFormat:@"%@%%", self.detailTask.progress];
    
}


- (void)refuseBtnDidClick {
    
    
}

- (void)agreeBtnDidClick {
    
    
}


@end
